package com.baturu.vin.gm.dal.dao;

import com.baturu.vin.gm.dto.GmPartsMappingDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

public interface GmPartsMappingDAO {

    @Select("<script>SELECT partsCode, btrPartsName, brand " +
            "FROM gm_parts_mapping " +
            "WHERE brand = #{brandName} and btrPartsName IN " +
            "<foreach item='item' index='index' collection='btrPartsNames' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<GmPartsMappingDTO> queryByBtrPartsName(@Param("brandName") String brandName, @Param("btrPartsNames") Collection<String> btrPartsNames);

    @Select("<script>select partsCode, btrPartsName, brand from gm_parts_mapping " +
            "where brand = #{brandName} and partsCode IN " +
            "<foreach item='item' index='index' collection='partsCodes' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<GmPartsMappingDTO> queryByPartsCode(@Param("brandName") String brandName, @Param("partsCodes") Collection<String> partsCodes);

    @Select({"SELECT DISTINCT t1.btrPartsName,t1.brand " ,
            "FROM gm_epc_cd_partdetail t  " ,
            "INNER JOIN gm_parts_mapping t1 " ,
            "on t1.partsCode = t.parts_code ",
            "WHERE t.cataLog_code = #{catalogCode} " ,
            "AND t.`Subject` = #{subject} " ,
            "AND t1.brand = #{brand} " ,
            "AND t.callout IN (${callout}) "})
    List<GmPartsMappingDTO> queryAssembly(@Param("catalogCode") String catalogCode, @Param("callout") String callout, @Param("brand") String brand, @Param("subject") String subject);

}